Welcome to coding exercise 50 and are the tuba that s part and our exercises file is still on the desktop
and we have free finance data exercises and to be on par to financial data analysis and now let's hope
exercise 15
and exercise 15 is all about creating analyzing and optimizing financial portfolios.
So first of all you have to import the stocks dataset and select the five year period here.
Then you should create 10000 random portfolios and the weights of the constituents of course have to
sum up to one and all weights must be between 0 and 1 and you should actually use the NPD at random
seed of 1 to 3 to get actually the very same results as I do in the solution.
And then you should calculate annualized the risk and return for the six stocks and also for the 10000
random portfolios and the calculation shall be based on daily returns simple returns and you should
also visualize this here and to make life easier.
You can also use the user defined function annualized risk and return.
And then you should assume that the approximate risk free assets showed a return of one point seven
percent.
So this could be a five year U.S. Treasury note.
And with this you can calculate the Sharpe ratio for the six stocks and for the 10000 random portfolios
and you should also visualize this sharp ratio as the third dimension of the graph with different colors.
And then you should also search for the max Sharpe rates for portfolio from the set of the 10000 random
portfolios and determine risk return and Sharpe ratio and then finally you have to determine the weights
for the constituents in the max to operate your portfolio.
And if you are computing power allows for this you can also increase the number of random portfolios
to for example 50000.
And by doing so your results are getting more exact on more reliable.
And then you might be able to answer the question of which stocks do you think have an actual rate of
zero in the real Max operator portfolio.
That can be derived with an optimization algorithm and it should also be able to identify highly concentrated
position in one of the stocks.
And of course you can also use the option to guided and instructed.
And finally there's also some hints here at the very end so that's accounting exercise safety and I
hope you have fun and feel free to have a look at the solution by.